package com.bob.common.resources;

import com.bob.common.DataStore;
import com.bob.common.bean.ResourcesRef;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件资源处理
 * @author heh
 */
public interface ResourcesExec {

    Log logger = new SystemStreamLog();
    /**
     * 初始化文件资源映射
     * @param resourcesRefs
     */
    default  void initResources(List<ResourcesRef> resourcesRefs){
        DataStore.getDataStore().getResourcesRefs().add(new ResourcesRef (File.separator+"src"+File.separator+"main"+File.separator+"resource",File.separator+"WEB-INF"+File.separator+"classes"));
        DataStore.getDataStore().getResourcesRefs().add(new ResourcesRef (File.separator+"src"+File.separator+"main"+File.separator+"resources",File.separator+"WEB-INF"+File.separator+"classes"));
        DataStore.getDataStore().getResourcesRefs().add(new ResourcesRef(File.separator+"src"+File.separator+"main"+File.separator+"webapp",""));
        DataStore.getDataStore().getResourcesRefs().add(new ResourcesRef(File.separator+"src"+File.separator+"main"+File.separator+"java",File.separator+"WEB-INF"+File.separator+"classes"));
        for (ResourcesRef resourcesRef : resourcesRefs.isEmpty()?new ArrayList<ResourcesRef>():resourcesRefs) {
            DataStore.getDataStore().getResourcesRefs().add(resourcesRef);
        }
        for (ResourcesRef resourcesRef :DataStore.getDataStore().getResourcesRefs()){
            logger.info(String.format("=== 初始化文件资源映射  %s ==> %s  ", resourcesRef.getS(),resourcesRef.getP()));
        }
    }

    /**
     *
     * @param baseDir 项目路径
     * @param patchOutPath patchOutPath/2021-08-07-12-12-54
     * @param finalName
     */
    void exec(File baseDir,File outputDirectory,File patchOutPath , String finalName);
}
